<?php defined('InShopNC') or exit('Access Invalid!');?>
<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3>活动商品模板</h3>
      <ul class="tab-base">
        <li><a href="javascript:;" class="current"><span>活动模板管理</span></a></li>
        <li><a href="index.php?act=goods_templates&op=addGt_class"><span>添加活动模板</span></a></li>
        <li><a href="index.php?act=goods_templates&op=goods_templates_list"><span>模板商品管理</span></a></li>
        <li><a href="index.php?act=goods_templates&op=goods_templates_add"><span>添加模板商品</span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <table class="table tb-type2" id="prompt">
    <tbody>
      <tr class="space odd">
        <th class="nobg" colspan="12"><div class="title"><h5><?php echo $lang['nc_prompts'];?></h5><span class="arrow"></span></div></th>
      </tr>
      <tr>
        <td>
          <ul>
            <li>先添加活动模板</li>
            <li>每次只能开启一个活动模板</li>
            <li>活动模板规定每一个模板商品个数</li>
            <li>每一次更换活动时，只需要在活动商品中链接的商品</li>
             <li>添加活动商品时，活动商品务必和对应的模板图片一致</li>
             <li>添加每一种类型的图片时，必须严格按照模板排列顺序添加</li>
          </ul>
        </td>
      </tr>
    </tbody>
  </table>
  <form method='post' id="list_form">
    <input type="hidden" name="form_submit" value="ok" />
    <input type="hidden" name="submit_type" id="submit_type" value="" />
    <input type="hidden" name="class_id" id="class_id">
    <table class="table tb-type2">
      <thead>
        <tr class="thead">
          <th></th>
          <th>模板id</th>
          <th>模板名称</th>
          <th>模板状态</th>
          <th>删除模板内所有内容</th>
         
        </tr>
      </thead>
      <tbody>
        <?php if (!empty($output['gt_class_list']) && is_array($output['gt_class_list'])) { ?>
        <?php foreach ($output['gt_class_list'] as $val) { ?>
           <tr class="hover edit">
              <td></td>
              <td class="w48 sort">
                <span nc_type="inline_edit" ajax_branch="class" ><?php echo $val['gt_class_id'];?></span>
              </td>
              <td class="name">
                <span nc_type="inline_edit" ajax_branch="class" ><?php echo $val['gt_class_name'];?></span>
                
              </td>
              <td class="name">
                <span nc_type="inline_edit" ajax_branch="class" ><a  data-id="<?php echo $val['gt_class_id'];?>" data="<?php echo $val['is_active']; ?>" href="javascript:void(0);" class='is_active'><?php if ( $val['is_active']==1){echo '开启';}else{echo "关闭";};?></a></span>
                
              </td>
              <td class="name">
                <span nc_type="inline_edit" ajax_branch="class" ><a  data-id="<?php echo $val['gt_class_id'];?>"  href="javascript:void(0);" class='delete_content'>确认删除</a></span>
                
              </td>
              
            </tr>
        <?php } ?>
        <?php }  ?>
        
      </tbody>
     
    </table>
  </form>
</div>
<script type="text/javascript">

$('.is_active').click(function(){
	var is_active=$(this).attr("data");
	var gs_tp_id=$(this).attr("data-id");
	get_goods(is_active,gs_tp_id);
});

$('.delete_content').click(function(){
	var gt_class_id=$(this).attr("data-id");
	firm(gt_class_id);
	
});

//弹出一个询问框，有确定和取消按钮  
function firm(gt_class_id) {  
    //利用对话框返回的值 （true 或者 false）  
    if (confirm("你确定删除吗？")) {  
    	delete_content(gt_class_id);
    }  
    else {  
        alert("取消操作");  
    }  

} 

/*
 * 删除模板下的所有内容
 */
function delete_content(gt_class_id){
	$.ajax({
	       type: "post",
	       data:{gt_class_id:gt_class_id},
	       url: "index.php?act=goods_templates&op=delete_content",
	       dataType: "json",
	       async: true,
	       success: function (data) {

		       if(data.status==1){
					alert("删除成功");
					location.reload();

		   		}else{
		   			alert("删除失败");
					location.reload();
			   	}
		      
		       
		   }

	    });
}

function get_goods(is_active,gs_tp_id){
	$.ajax({
	       type: "post",
	       data:{is_active:is_active,gs_tp_id:gs_tp_id},
	       url: "index.php?act=goods_templates&op=change_status",
	       dataType: "json",
	       async: true,
	       success: function (data) {

		       if(data.status==1){
					alert("状态修改成功");
					location.reload();

		   		}else{
		   			alert("状态修改失败");
					location.reload();
			   	}
		      
		       
		   }

	    });
}

</script>

